<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录页面</title>
<!-- 引入bootstrap样式 -->
<link rel="stylesheet" type="text/css" href="/cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.min.css"  />
<style>
	.loginForm {
            /*边框高度*/
            height: 300px;
            /*边框宽度*/
            width: 500px;
            /*边框颜色*/
            border: #4d4d4d solid 1px;
            /*边框圆角*/
            border-radius: 4px;
            /*阴影 水平方向，竖直方向，模糊距离*/
            box-shadow: 5px 5px 5px #4d4d4d;
            /*上边界距离*/
            margin-top: 300px;
            /*左边界距离：自动*/
            margin-left: auto;
            /*右边界距离：自动*/
            margin-right: auto;
            /*用户名、密码间距*/
            padding: 20px 40px;
        }
</style>
</head>
<body>
<div class="loginForm" >
	<div class="form-group" >
		<label for="code">账号</label>
		<input type="text" class="form-control" id="code" name="code" placeholder="账号">
	</div>
	<br/>
	<div class="form-group" >
		<label for="code">密码</label>
		<input type="password" class="form-control" id="password" name="password" placeholder="密码">
	</div>
	<br/>
	<div style="text-align: center;">
		<button id="dengLu" onclick="login()" class="btn btn-primary">登录</button>
		<span></span>
		<button id="zhuCe" onclick="zhuce()" class="btn btn-default">注册</button>
	</div>
</div>
<script src="/js/jquery-3.3.1.min.js" ></script>
<script type="text/javascript">
function login(){
	if($("#code").val() == ""){
		alert("请输入账号");
		return;
	}
	if($("#password").val() == ""){
		alert("请输入密码");
		return;
	}
	// 登录
	$.ajax({
		url:"/bsUserCtrl/login",
		type:"POST",
		dataType:"json",
		cache:false,
		data:{
			"code":$("#code").val(),
			"password":$("#password").val()
		},
		success:function(data){
			if(data.code == "10001"){
				alert("登录成功");
				location.href="/index.html";
			}else{
				alert(data.message);
			}
		},
		error : function(request, textStatus, errorThrown) {
			alert("异常，请联系管理员");
		}
	});
}

function zhuce(){
	location.href="/mgmt/bsUser/bsUserAdd.jsp";
}
$(function(){
	// 如果已经登录，则跳转到首页
	$.ajax({
		url:"/bsUserCtrl/status",
		type:"POST",
		dataType:"json",
		success:function(data){
			if(data.code=="10001"){
				location.href="/index.html";
			}
		},
		error:function(a,b,c){
			alert("异常，请联系管理员");
		}
	});
});
</script>
</body>
</html>